package com.demo.dao;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.springframework.data.jpa.domain.Specification;

import com.demo.entity.Course;
import com.demo.entity.CourseDTO;
import com.demo.entity.CourseSection;

public class CourseSectionSpec implements Specification<CourseSection>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public Predicate toPredicate(Root<CourseSection> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
		
		// 多表连接获取查询参数，要去查询 章节的数据，附带查所属的课程的数据
        Join<Course, CourseSection> join = root.join("course", JoinType.LEFT);   // from 课程表 JOIN 章节表 ON 关联字段
 
        //return cb.like(join.get("courseName"), "%Java%");  // where 课程表.courseName like '%Java%
        
		return cb.equal(join.get("id"), 2000); // where 课程表.id = 2000
	}

}
